function QueryPlugin(queries) {
  function onConstruct(editor, next) {
    for (const query in queries) {
      editor.registerQuery(query);
    }
    next();
  }

  function onQuery(query, editor, next) {
    const { type, args } = query;
    const fn = queries[type];
    if (!fn) {
      return next();
    }
    return editor.query(fn, ...args);
  }

  return { onConstruct, onQuery };
}

export default QueryPlugin;
